<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MVCWeb.Models.VendorCommunityAds>>" %>

<%@ Register Src="~/Views/Menu/MainMenu.ascx" TagName="MainMenu" TagPrefix="mmuc" %>

<%@ Register Src="~/Views/Shared/LogOnUserControl.ascx" TagName="LogOnUserControl" TagPrefix="louc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <script language="javascript" type="text/javascript">
        function deleteRecord(vendorId, communityId, adsId) {
            if (confirm("Are you sure to delete this ads of community?")) {
                // Perform delete
                var action = '<%= Url.Action("Delete", "VendorCommunityAds") %>/?vendorId=' + vendorId + '&communityId=' + communityId + '&adsId=' + adsId;
                var request = new Sys.Net.WebRequest();
                request.set_httpVerb("POST");
                request.set_url(action);
                request.add_completed(deleteCompleted);
                request.invoke();
            }
        }

        function deleteCompleted() {
            // Reload page  
            window.location.reload();
        }    
    </script>

    <louc:LogOnUserControl ID="LogOnUserControl1" runat="server" />
   <!-- BEGIN: MainMenu -->
    <mmuc:MainMenu ID="MainMenu1" runat="server" />
    <!-- END: MainMenu -->
    <h2>
        Index of Ads for Community</h2>
    <table cellpadding="4" cellspacing="1" border="0" width="100%" class="DataTable">
        <tr>
            <th>
                Vendor
            </th>
            <th>
                Ads
            </th>
            <th>
                Community
            </th>
            <th>
                Active
            </th>
            <th>
                Started
            </th>
            <th>
                Ended
            </th>
            <th>
            </th>
        </tr>
        <% foreach (var item in Model)
           { %>
        <tr>
            <td>
                <%= item.Vendor.VendorName %>
            </td>
            <td>
                <%= item.Ads.Type %>
            </td>
            <td>
                <%= item.Community.Name %>
            </td>
            <td align="center">
                <%= Html.CheckBox("Active", item.Active.Value) %>
            </td>
            <td>
                <%= item.Started.Value.ToShortDateString() %>
            </td>
            <td>
                <%= item.Ended.Value.ToShortDateString() %>
            </td>
            <td style="white-space:nowrap">
                <a href='<%= Url.Action("Edit", "VendorCommunityAds", new { VendorId = item.VendorId, CommunityId = item.CommunityId, AdsId = item.AdsId }) %>'>Edit</a> | <a onclick="deleteRecord(<%= item.VendorId%>, <% = item.CommunityId %>, <%= item.AdsId %>)" href="JavaScript:void(0)">Delete</a>
            </td>
        </tr>
        <% } %>
    </table>
    <p>
        <%= Html.ActionLink("Setup new Ads", "Create") %> | <%= Html.ActionLink("Setup new Ads for multi community", "Setup") %>
    </p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server">
</asp:Content>
